package org.game.manager;

import org.bean.GameServerInfo;
import org.game.cache.OnlinePlayerCache;
import org.game.cache.ServerCache;
import org.game.constant.GameConstant;
import org.utils.RemoteUtil;

import com.sojoys.artifact.constant.ConfigConstant;
import com.sojoys.artifact.core.IServer;
import com.sojoys.artifact.manager.PropManager;
import com.sojoys.artifact.tools.ToolOS;

/**
 * @author : DengYing
 * @CreateDate : 2017年12月16日 下午12:20:59
 * @Description ：游戏服务器管理器
 */
public class GameServerManager {
	private GameServerManager() {
	}

	private static GameServerManager ME = new GameServerManager();

	public static GameServerManager me() {
		return ME;
	}
	
	// 向登陆服务器注册
	public void registerGameServerInfo(){
		GameServerInfo gameServerInfo = createGameServerInfo();
		
		RemoteUtil.loginAsyn().registerGameServerInfo(gameServerInfo);
	}

	
	private GameServerInfo createGameServerInfo() {
		// 服务器信息
		GameServerInfo gameServerInfo = new GameServerInfo();
		gameServerInfo.setId(PropManager.get(GameConstant.GAME_SERVER_ID));
		gameServerInfo.setOnlineCount(OnlinePlayerCache.getOnlineCount());
		gameServerInfo.setPlayerCount(ServerCache.getPlayerCount());
		gameServerInfo.setStatus(IServer.SERVER_STATUS.getCode());
		// 网络
		gameServerInfo.setLocalHost(ToolOS.getOsLocalHostIp());
		gameServerInfo.setRemoteHost(PropManager.get(GameConstant.REMOTE_HOST));
		gameServerInfo.setSocketPort(PropManager.getInt(ConfigConstant.SOCKET_PORT));
		gameServerInfo.setHttpPort(PropManager.getInt(ConfigConstant.HTTP_PORT));
		// 内存
		gameServerInfo.setOsPhysicalMemory((int) ToolOS.getOsPhysicalMemory());
		gameServerInfo.setOsPhysicalFreeMemory((int) ToolOS.getOsPhysicalFreeMemory());
		gameServerInfo.setJvmTotalMemory((int) ToolOS.getJvmTotalMemory());
		gameServerInfo.setJvmFreeMemory((int) ToolOS.getJvmFreeMemory());
		gameServerInfo.setJvmMaxMemory((int) ToolOS.getJvmMaxMemory());
		// CPU 信息
		gameServerInfo.setOsCpuNumber(ToolOS.getOsCpuNumber());
		gameServerInfo.setOscpuRatio(ToolOS.getOscpuRatio());
		
		gameServerInfo.setInfoTime(System.currentTimeMillis());
		return gameServerInfo;
	}
}
